﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace SelfMadeMillionaire.Core
{
	public class PasswordUtility
	{
		public static string GetPasswordHash(string password)
		{
			SHA1 sha = new SHA1CryptoServiceProvider();

			byte[] passwordBytes = System.Text.Encoding.Unicode.GetBytes(password);
			return Convert.ToBase64String(sha.ComputeHash(passwordBytes));
		}

		public static string GeneratePassword()
		{
			int passwordLength = 6;
			string[] strCharacters = {
					                         	"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "e", "f", "g", "h",
					                         	"i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
					                         };
			Random rGen = new Random();
			int p = 0;
			string strPass = "";
			for (int x = 0; x <= passwordLength; x++)
			{
				p = rGen.Next(0, 35);
				strPass += strCharacters[p];
			}

			return strPass;
		}
	}
}
